package com.jinduplan.planmanager.ui.activity.project

import android.app.Dialog
import android.content.Intent
import android.os.Parcelable
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cxz.kotlin.baselibs.adapter.CustomRecyclerAdapter
import com.cxz.kotlin.baselibs.adapter.ViewHolder
import com.cxz.kotlin.baselibs.base.BaseMvpActivity
import com.cxz.kotlin.baselibs.utils.GsonHelper
import com.cxz.kotlin.baselibs.widget.CustomToast
import com.jinduplan.planmanager.R
import com.jinduplan.planmanager.bean.*
import com.jinduplan.planmanager.mvp.contract.ProjectUploadDetailContract
import com.jinduplan.planmanager.mvp.presenter.ProjectUploadDetailPresenter
import com.jinduplan.planmanager.utils.CustomRecyclerFilterableAdapter
import com.jinduplan.planmanager.utils.ResUtil
import com.jinduplan.planmanager.widgets.ComfirCancelDialog
import com.jinduplan.planmanager.widgets.datepicker.CustomDatePicker
import com.jinduplan.planmanager.widgets.datepicker.DateFormatUtils
import kotlinx.android.synthetic.main.activity_project.back
import kotlinx.android.synthetic.main.activity_project.recyclerView
import kotlinx.android.synthetic.main.activity_project_upload_detail.*
import org.jetbrains.anko.sdk27.coroutines.textChangedListener


class ProjectUploadDetailActivity() :
    BaseMvpActivity<ProjectUploadDetailContract.View, ProjectUploadDetailContract.Presenter>(),
    ProjectUploadDetailContract.View {
    private var typeDialog: Dialog? = null
    private var mDatePicker: CustomDatePicker? = null
    private var project_id: Int? = 0
    private var projectBeanList: ArrayList<ProjectUploadDetailBean.DataBean>? = null
    private var newProjectBeanList: ArrayList<NewProjectUploadDetailBean.BuildingBean>? = null
    private var buildingBeanList: ArrayList<BuildingBean>? = null
    private var building_id: Int? = 0
    private var facadeBeanList: ArrayList<FacadeBean>? = null
    private var facade_id: Int? = 0
    private var hangingBlueBeanList: ArrayList<HangingBlueBean>? =
        null
    private var hanging_blue_id: Int? = 0
    private var labourBeanList: ArrayList<NewProjectUploadDetailBean.LabourBean>? = null
    private var workmanShipBeanList: ArrayList<NewProjectUploadDetailBean.BuildingBean.FacadeBean.HangingBlueBean.WorkmanshipBean>? =
        null
//    private var constructionList: ArrayList<NewProjectUploadDetailBean.BuildingBean.FacadeBean.HangingBlueBean.WorkmanshipBean.ConstructionBean>? =
//        null
    private var user_id: Int? = 0
    private var workmanship_id: Int? = 0
    private var construction_id: Int? = 0
    private var mapData: HashMap<String, ArrayList<String>>? = null
    private var requestUserArrList: ArrayList<RequestPutProjectBean.UserArrBean>? = null
    private var dialog: ComfirCancelDialog? = null
    private var isZero: Boolean = false


    override fun createPresenter(): ProjectUploadDetailContract.Presenter =
        ProjectUploadDetailPresenter()

    override fun start() {
        buildingBeanList = ArrayList()
        facadeBeanList = ArrayList()
        hangingBlueBeanList = ArrayList()
        labourBeanList = ArrayList()
        workmanShipBeanList = ArrayList()
        projectBeanList = ArrayList()
        newProjectBeanList = ArrayList()
        requestUserArrList = ArrayList()
//        constructionList = ArrayList()

        recyclerView.adapter = object :
            CustomRecyclerAdapter<NewProjectUploadDetailBean.BuildingBean.FacadeBean.HangingBlueBean.WorkmanshipBean>(
                this, R.layout.item_project_upload_detail, workmanShipBeanList
            ) {
            override fun convert(
                holder1: ViewHolder?,
                t1: NewProjectUploadDetailBean.BuildingBean.FacadeBean.HangingBlueBean.WorkmanshipBean?,
                position: Int
            ) {

                holder1?.setText(R.id.tv_name, t1?.workmanship_name)
//                constructionList!!.clear()
//                constructionList!!.addAll(t1?.construction!!)

//                var item_recyclerView = holder1?.getView<RecyclerView>(R.id.item_recyclerView)
                var ll_content = holder1?.getView<LinearLayout>(R.id.ll_content)
                ll_content!!.removeAllViews()
                for (i in 0 until workmanShipBeanList!![position].construction!!.size) {
                    var layoutInflater = LayoutInflater.from(applicationContext)
                    var view = layoutInflater.inflate(R.layout.item_item_project_detail, null)
                    view.setTag(i)
                    ll_content!!.addView(view)
                    var tv_category = view.findViewById<TextView>(R.id.tv_category)
                    tv_category.text = workmanShipBeanList!![position].construction!![i].construction_process

                    var tv_number = view.findViewById<TextView>(R.id.tv_number)
                    tv_number.text = "未施工${workmanShipBeanList!![position].construction!![i].uncompleted_area}m²"

                    var editText = view.findViewById<EditText>(R.id.editText)
//                    editText.text = constructionList!![i].editTextStr
                    // editText.setSelection(constructionList!![i].editTextStr!!.length)

                    //Log.e("constructionList", "----->" +GsonHelper.toJson(constructionList))
                    if (workmanShipBeanList!![position].construction!![i].isThan == true) {
                        editText.setTextColor(ResUtil.getC(R.color.than_text_red))
                    } else {
                        editText.setTextColor(ResUtil.getC(R.color.black111_jdy))
                    }
                    editText?.textChangedListener {
                        onTextChanged { charSequence, g, i2, i3 ->
//                            Log.e("textChangedListener","----->"+charSequence.toString())
//                            Log.e("textChangedListener","----->"+ t1?.construction!![i].construction_process)
                            workmanShipBeanList!![position].construction!![i].editTextStr = charSequence.toString()
                            if (!charSequence.toString().isEmpty()) {
                                if (charSequence.toString()
                                        .toFloat() > (t1?.construction!![i].uncompleted_area)!!.toFloat()
                                ) {
                                    CustomToast(
                                        applicationContext,
                                        true,
                                        "您已经超过额定面积"
                                    ).show()
                                    workmanShipBeanList!![position].construction!![i].isThan = true
                                    editText?.setTextColor(
                                        ResUtil.getC(R.color.than_text_red)
                                    )
                                } else {
                                    workmanShipBeanList!![position].construction!![i].isThan = false
                                    editText?.setTextColor(
                                        ResUtil.getC(R.color.black111_jdy)
                                    )
                                }
                            }
                        }

                    }
                }
            }

        }
        recyclerView.layoutManager = LinearLayoutManager(this)

        project_id = intent.getIntExtra("project_id", 0)
        mPresenter?.getNewProjectUploadDetailList(project_id!!)


    }


    override fun onDestroy() {
        super.onDestroy()
        mDatePicker?.onDestroy()
        if (typeDialog != null) {
            typeDialog?.dismiss()
        }
        if (dialog != null) {
            dialog?.dismiss()
        }
    }

    override fun initView() {
        super.initView()
        setStatusBarColor(ResUtil.getC(R.color.white))

        back.setOnClickListener {
            finish()
        }
        tv_person.setOnClickListener {
            showTypeDialog(1)
        }
        tv_build.setOnClickListener {
            showTypeDialog(2)
        }
        tv_surface.setOnClickListener {
            showTypeDialog(3)
        }
        tv_basketNum.setOnClickListener {
            showTypeDialog(4)
        }
        initDatePicker()
        ll_date.setOnClickListener {
            mDatePicker?.show(tv_calendar.text.toString())
        }

        bt_upload.setOnClickListener {
            dialog = ComfirCancelDialog(this).setContent("是否上传", "上传后您的数据将会被记录") {
                var requestBean = RequestPutProjectBean()
                requestBean.project_id = project_id!!
                requestBean.completion_date = tv_calendar.text.toString()
                requestBean.user_arr = ArrayList()
                isZero = false
                var uerArr = ArrayList<RequestPutProjectBean.UserArrBean>()
                if (requestUserArrList?.size!! > 0) {
                    requestBean.user_arr.addAll(requestUserArrList!!)

                } else {
                    requestBean.user_arr.addAll(getProjectUpItemData())
                }
                //requestBean.user_arr.addAll(getEditIsEmpty(uerArr))

//                Log.e("requestBean", "---->" + GsonHelper.toJson(requestBean))

                mPresenter?.putProjectUpload(requestBean)

            }
            dialog?.show()
        }

        bt_staging.setOnClickListener {
            requestUserArrList?.addAll(getProjectUpItemData())
            removeListDuplicate(requestUserArrList as ArrayList<Any>)
            CustomToast(this, true, "数据已暂存").show()
        }
    }

    override fun attachLayoutRes(): Int {
        return R.layout.activity_project_upload_detail
    }

    private fun initDatePicker() {
        val beginTimestamp: Long = DateFormatUtils.str2Long("2000-01-01", false)
        val endTimestamp = System.currentTimeMillis()
        tv_calendar.setText(DateFormatUtils.long2Str(endTimestamp, false))

        // 通过时间戳初始化日期，毫秒级别
        mDatePicker = CustomDatePicker(
            this,
            { timestamp ->
                tv_calendar.setText(
                    DateFormatUtils.long2Str(timestamp, false)
                )
            }, beginTimestamp, endTimestamp
        )
        // 不允许点击屏幕或物理返回键关闭
        mDatePicker?.setCancelable(false)
        // 不显示时和分
        mDatePicker?.setCanShowPreciseTime(false)
        // 不允许循环滚动
        mDatePicker?.setScrollLoop(false)
        // 不允许滚动动画
        mDatePicker?.setCanShowAnim(false)
    }


    private fun showTypeDialog(type: Int) {
        typeDialog = Dialog(this, R.style.BottomDialog)
        val contentView: View =
            LayoutInflater.from(this).inflate(R.layout.dialog_project_upload_detail, null)
        typeDialog!!.setContentView(contentView)
        val layoutParams: ViewGroup.LayoutParams = contentView.layoutParams
        layoutParams.width = resources.displayMetrics.widthPixels
        contentView.layoutParams = layoutParams
        typeDialog!!.setCanceledOnTouchOutside(true)

        typeDialog!!.window?.setGravity(Gravity.BOTTOM)
        typeDialog!!.window?.setWindowAnimations(R.style.BottomDialog_Animation)
        typeDialog!!.show()
        //1 人员选择 2 楼栋选择 3 里面选择 4 吊篮选择
        var projectList = ArrayList<Any>()
        projectList.clear()
        when (type) {
            1 -> {
                typeDialog!!.findViewById<TextView>(R.id.tv_type).text = "人员选择"
                projectList.addAll(labourBeanList!!)
                if (projectList.size > 0) {
                    var isSelect = false
                    for (i in 0 until projectList.size) {
                        if ((projectList[i] as NewProjectUploadDetailBean.LabourBean).isSelect == true) {
                            isSelect = true
                        }
                    }
                    if (!isSelect) {
                        (projectList[0] as NewProjectUploadDetailBean.LabourBean).isSelect =
                            true
                        user_id =
                            (projectList[0] as NewProjectUploadDetailBean.LabourBean).labour_id
                        tv_person.text =
                            (projectList[0] as NewProjectUploadDetailBean.LabourBean).full_name
                    }
                }
            }
            2 -> {
                typeDialog!!.findViewById<TextView>(R.id.tv_type).text = "楼栋选择"
                projectList.addAll(buildingBeanList!!)
                if (projectList.size > 0) {
                    var isSelect = false
                    for (i in 0 until projectList.size) {
                        if ((projectList[i] as BuildingBean).isSelect == true) {
                            isSelect = true
                        }
                    }
                    if (!isSelect) {
                        (projectList[0] as BuildingBean).isSelect =
                            true
                        building_id = (projectList[0] as BuildingBean).id
                        tv_build.text =
                            (projectList[0] as BuildingBean).building_name
                    }

                }
            }
            3 -> {
                typeDialog!!.findViewById<TextView>(R.id.tv_type).text = "立面选择"
                projectList.addAll(facadeBeanList!!)
                if (projectList.size > 0) {
                    var isSelect = false
                    for (i in 0 until projectList.size) {
                        if ((projectList[i] as FacadeBean).isSelect == true) {
                            isSelect = true
                        }
                    }
                    if (!isSelect) {
                        (projectList[0] as FacadeBean).isSelect = true
                        facade_id =
                            (projectList[0] as FacadeBean).id
                        tv_surface.text =
                            (projectList[0] as FacadeBean).facade_name
                    }
                }
            }
            4 -> {
                typeDialog!!.findViewById<TextView>(R.id.tv_type).text = "吊篮选择"
                projectList.addAll(hangingBlueBeanList!!)
                if (projectList.size > 0) {
                    var isSelect = false
                    for (i in 0 until projectList.size) {
                        if ((projectList[i] as HangingBlueBean).isSelect == true) {
                            isSelect = true
                        }
                    }
                    if (!isSelect) {
                        (projectList[0] as HangingBlueBean).isSelect =
                            true
                        hanging_blue_id =
                            (projectList[0] as HangingBlueBean).id
                        tv_basketNum.text =
                            (projectList[0] as HangingBlueBean).hanging_blue_name
                    }
                }
            }
        }
        typeDialog!!.findViewById<ImageView>(R.id.iv_close)
            .setOnClickListener {
                if (type != 1) {
                    getWorkmanShipList(building_id!!, facade_id!!, hanging_blue_id!!)
                }
                typeDialog!!.dismiss()
            }


        val recyclerView = typeDialog!!.findViewById<RecyclerView>(R.id.recyclerView)

        recyclerView.adapter = object : CustomRecyclerFilterableAdapter<Any>(
            this, R.layout.item_rv_choose, projectList
        ) {
            override fun convert(holder: ViewHolder?, t: Any?, position: Int) {
                recyclerView.adapter as CustomRecyclerFilterableAdapter<Any>

                when (type) {
                    1 -> {
                        t as NewProjectUploadDetailBean.LabourBean
                        val textName = holder?.getView<TextView>(R.id.tv_name)
                        textName?.text = t?.full_name
                        textName?.isSelected = t?.isSelect == true
                        holder?.setVisible(R.id.iv_choose, t?.isSelect == true)
                        holder?.convertView?.setOnClickListener {
                            var projects = ArrayList<Any>()
                            projects.clear()
                            projects.addAll((recyclerView.adapter as CustomRecyclerFilterableAdapter<Any>).data)
                            for (index in 0 until projects.size) {
                                (projects[index] as NewProjectUploadDetailBean.LabourBean).isSelect =
                                    false
                            }
                            (projects[position] as NewProjectUploadDetailBean.LabourBean).isSelect =
                                true
                            tv_person.text =
                                (projects[position] as NewProjectUploadDetailBean.LabourBean).full_name
                            user_id =
                                (projects[position] as NewProjectUploadDetailBean.LabourBean).labour_id
                            recyclerView.adapter?.notifyDataSetChanged()
                            if (type != 1) {
                                getProjectWorkmanShipData()
                            }
                            typeDialog!!.dismiss()
                        }
                    }
                    2 -> {
                        t as BuildingBean
                        val textName = holder?.getView<TextView>(R.id.tv_name)
                        textName?.text = t?.building_name
                        textName?.isSelected = t?.isSelect == true
                        holder?.setVisible(R.id.iv_choose, t?.isSelect == true)
                        holder?.convertView?.setOnClickListener {
                            var projects = ArrayList<Any>()
                            projects.addAll((recyclerView.adapter as CustomRecyclerFilterableAdapter<Any>).data)
                            for (index in 0 until projects.size) {
                                (projects[index] as BuildingBean).isSelect =
                                    false
                            }
                            (projects[position] as BuildingBean).isSelect =
                                true
                            tv_build.text =
                                (projects[position] as BuildingBean).building_name
                            building_id =
                                (projects[position] as BuildingBean).id
                            recyclerView.adapter?.notifyDataSetChanged()
                            if (type != 1) {
                                getFacadeList(building_id!!)
                                removeListDuplicate(facadeBeanList as ArrayList<Any>)
                                if (facadeBeanList?.size!! > 0) {
                                    facadeBeanList?.get(0)?.isSelect = true
                                    tv_surface.text = facadeBeanList?.get(0)?.facade_name
                                    facade_id = facadeBeanList?.get(0)?.id
                                }
                                getHangingBlueList(building_id!!, facade_id!!)
                                removeListDuplicate(hangingBlueBeanList as ArrayList<Any>)
                                if (hangingBlueBeanList?.size!! > 0) {
                                    hangingBlueBeanList?.get(0)?.isSelect = true
                                    tv_basketNum.text =
                                        hangingBlueBeanList?.get(0)?.hanging_blue_name
                                    hanging_blue_id = hangingBlueBeanList?.get(0)?.id
                                }
                                getWorkmanShipList(building_id!!, facade_id!!, hanging_blue_id!!)
                            }
                            typeDialog!!.dismiss()
                        }
                    }
                    3 -> {
                        t as FacadeBean
                        val textName = holder?.getView<TextView>(R.id.tv_name)
                        textName?.text = t?.facade_name
                        textName?.isSelected = t?.isSelect == true
                        holder?.setVisible(R.id.iv_choose, t?.isSelect == true)
                        holder?.convertView?.setOnClickListener {
                            var projects = ArrayList<Any>()
                            projects.addAll((recyclerView.adapter as CustomRecyclerFilterableAdapter<Any>).data)
                            for (index in 0 until projects.size) {
                                (projects[index] as FacadeBean).isSelect =
                                    false
                            }
                            (projects[position] as FacadeBean).isSelect =
                                true
                            tv_surface.text =
                                (projects[position] as FacadeBean).facade_name
                            facade_id =
                                (projects[position] as FacadeBean).id
                            recyclerView.adapter?.notifyDataSetChanged()
                            if (type != 1) {
                                getHangingBlueList(building_id!!, facade_id!!)
                                removeListDuplicate(hangingBlueBeanList as ArrayList<Any>)
                                if (hangingBlueBeanList?.size!! > 0) {
                                    hangingBlueBeanList?.get(0)?.isSelect = true
                                    tv_basketNum.text =
                                        hangingBlueBeanList?.get(0)?.hanging_blue_name
                                    hanging_blue_id = hangingBlueBeanList?.get(0)?.id
                                }
                                getWorkmanShipList(building_id!!, facade_id!!, hanging_blue_id!!)
                            }
                            typeDialog!!.dismiss()
                        }
                    }
                    4 -> {
                        t as HangingBlueBean
                        val textName = holder?.getView<TextView>(R.id.tv_name)
                        textName?.text = t?.hanging_blue_name
                        textName?.isSelected = t?.isSelect == true
                        holder?.setVisible(R.id.iv_choose, t?.isSelect == true)
                        holder?.convertView?.setOnClickListener {
                            var projects = ArrayList<Any>()
                            projects.addAll((recyclerView.adapter as CustomRecyclerFilterableAdapter<Any>).data)
                            for (index in 0 until projects.size) {
                                (projects[index] as HangingBlueBean).isSelect =
                                    false
                            }
                            (projects[position] as HangingBlueBean).isSelect =
                                true
                            tv_basketNum.text =
                                (projects[position] as HangingBlueBean).hanging_blue_name
                            hanging_blue_id =
                                (projects[position] as HangingBlueBean).id
                            recyclerView.adapter?.notifyDataSetChanged()
                            if (type != 1) {
                                getWorkmanShipList(building_id!!, facade_id!!, hanging_blue_id!!)
                            }
                            typeDialog!!.dismiss()
                        }
                    }
                }
            }
        }
        typeDialog!!.findViewById<EditText>(R.id.ed_search).addTextChangedListener(object :
            android.text.TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                (recyclerView.adapter as CustomRecyclerFilterableAdapter<Any>).filter.filter(s.toString())
            }

            override fun afterTextChanged(s: Editable?) {
            }
        })
        recyclerView.layoutManager = LinearLayoutManager(this)
    }

    override fun setProjectUploadDetailListData(bean: ProjectUploadDetailBean) {
//        mapData = HashMap()
//        projectBeanList?.clear()
//        projectBeanList?.addAll(bean.data)
//        val buildingNameList = ArrayList<String>()
//
//        for (index in 0 until projectBeanList?.size!!) {
//            buildingNameList.add(projectBeanList?.get(index)?.building!!.building_name)
//        }
//        buildingBeanList?.addAll(bean.map.getBuild()!!)
//        facadeBeanList?.addAll(bean.map.getFacade()!!)
//        hangingBlueBeanList?.addAll(bean.map.getHanging_blue()!!)
//        removeListDuplicate(buildingBeanList as ArrayList<Any>)
//        removeListDuplicate(facadeBeanList as ArrayList<Any>)
//        removeListDuplicate(hangingBlueBeanList as ArrayList<Any>)
//
//
//
//        if (buildingBeanList?.size!! > 0) {
//            buildingBeanList?.get(0)?.isSelect = true
//            tv_build.text = buildingBeanList?.get(0)?.building_name
//            building_id = buildingBeanList?.get(0)?.id
//        }
//
//        if (facadeBeanList?.size!! > 0) {
//            facadeBeanList?.get(0)?.isSelect = true
//            tv_surface.text = facadeBeanList?.get(0)?.facade_name
//            facade_id = facadeBeanList?.get(0)?.id
//        }
//        if (hangingBlueBeanList?.size!! > 0) {
//            hangingBlueBeanList?.get(0)?.isSelect = true
//            tv_basketNum.text = hangingBlueBeanList?.get(0)?.hanging_blue_name
//            hanging_blue_id = hangingBlueBeanList?.get(0)?.id
//        }
//        mPresenter?.getProjectLabour(project_id!!)
    }

    override fun setProjectLabour(labour: ProjectLabour) {
//        labourBeanList?.addAll(labour.data)
//        if (labourBeanList?.size!! > 0) {
//            labourBeanList!![0].isSelect = true
//            tv_person.text = labourBeanList!![0].full_name
//            user_id = labourBeanList!![0].id
//        }
//        removeListDuplicate(labourBeanList as ArrayList<Any>)
//        getProjectWorkmanShipData()
    }

    private fun getProjectWorkmanShipData() {
        mPresenter?.getProjectWorkmanShip(
            1,
            500,
            hanging_blue_id!!,
            project_id!!,
            building_id!!,
            getWorkmanShipId(projectBeanList!!),
            facade_id!!
        )
    }

    private fun getProjectUpItemData(): ArrayList<RequestPutProjectBean.UserArrBean> {
        var userArrList = ArrayList<RequestPutProjectBean.UserArrBean>()
        Log.e("gyc", GsonHelper.toJson(workmanShipBeanList))
        for (i in 0 until workmanShipBeanList!!.size) {
            var userArr = RequestPutProjectBean.UserArrBean()
            userArr.user_id = user_id!!
            userArr.construction_arr = ArrayList()
            var constructionArr = ArrayList<RequestPutProjectBean.UserArrBean.ConstructionArrBean>()
            for (j in 0 until workmanShipBeanList!![i].construction.size) {
                if (!workmanShipBeanList!![i].construction[j].editTextStr.isEmpty()) {
                    var constructionArrBean =
                        RequestPutProjectBean.UserArrBean.ConstructionArrBean()
                    constructionArrBean.construction_id =
                        workmanShipBeanList!![i].construction[j].id
                    if (workmanShipBeanList!![i].construction[j].editTextStr.isEmpty()) {
                        constructionArrBean.completion_area = 0.toFloat()
                    } else {
                        constructionArrBean.completion_area =
                            workmanShipBeanList!![i].construction[j].editTextStr.toFloat()
                    }
                    constructionArrBean.usage_amount =
                        workmanShipBeanList!![i].construction[j].usage_amount.toString()
                    if (constructionArrBean.completion_area != 0.toFloat()) {
                        constructionArr.add(constructionArrBean)
                    }
                }
            }
            if (constructionArr.size > 0) {
                userArr.construction_arr.addAll(constructionArr)
                userArrList.add(userArr)
            }
        }
        return userArrList
    }

    private fun getEditIsEmpty(user_arr: List<RequestPutProjectBean.UserArrBean>): ArrayList<RequestPutProjectBean.UserArrBean> {
        var newUserArr = ArrayList<RequestPutProjectBean.UserArrBean>()
        for (i in 0 until user_arr!!.size) {
            for (k in 0 until user_arr[i].construction_arr.size) {
                if (user_arr[i].construction_arr[k].completion_area.toInt() != 0 ||
                    user_arr[i].construction_arr[k].completion_area != 0.toFloat()
                ) {
                    newUserArr.add(user_arr[i])
                    //isZero=true
                }
            }

        }
        return newUserArr

    }

    override fun setProjectWorkmanShip(projectWorkmanShip: ProjectWorkmanShip) {
//        workmanShipBeanList?.clear()
//        if (projectWorkmanShip.data.size > 0) {
//            tv_noWorkmanShipData.visibility = View.GONE
//            recyclerView.visibility = View.VISIBLE
//            workmanShipBeanList?.addAll(projectWorkmanShip.data)
//        } else {
//            tv_noWorkmanShipData.visibility = View.VISIBLE
//            recyclerView.visibility = View.GONE
//        }
//        recyclerView.adapter?.notifyDataSetChanged()
    }

    override fun putProjectUploadSuccess(data: ArrayList<ProjectUploadSuccessBean>) {
        finish()
        val intent = Intent(this, ProjectUploadSignActivity::class.java)
        intent.putExtra("project_upload_data", data)
        startActivity(intent)
    }

    override fun setNewProjectUploadDetailListData(projectData: NewProjectUploadDetailBean) {
        tvTitle.text = projectData.project_name
        if (projectData.labour.size > 0) {
            labourBeanList!!.clear()
            labourBeanList!!.addAll(projectData.labour)
            labourBeanList!![0].isSelect = true
            tv_person.text = labourBeanList!![0].full_name
            user_id = labourBeanList!![0].labour_id
            removeListDuplicate(labourBeanList as ArrayList<Any>)
        }
        if (projectData.building.size > 0) {
            newProjectBeanList!!.clear()
            newProjectBeanList!!.addAll(projectData.building)
            buildingBeanList!!.clear()
            for (i in 0 until projectData.building.size) {
                var bean = BuildingBean()
                bean.id = projectData.building[i].id
                bean.building_name = projectData.building[i].building_name
                buildingBeanList!!.add(bean)
            }
            removeListDuplicate(buildingBeanList as ArrayList<Any>)
            buildingBeanList?.get(0)?.isSelect = true
            tv_build.text = buildingBeanList?.get(0)?.building_name
            building_id = buildingBeanList?.get(0)?.id

            getFacadeList(building_id!!)
            removeListDuplicate(facadeBeanList as ArrayList<Any>)
            if (facadeBeanList?.size!! > 0) {
                facadeBeanList?.get(0)?.isSelect = true
                tv_surface.text = facadeBeanList?.get(0)?.facade_name
                facade_id = facadeBeanList?.get(0)?.id
            }
            getHangingBlueList(building_id!!, facade_id!!)
            removeListDuplicate(hangingBlueBeanList as ArrayList<Any>)
            if (hangingBlueBeanList?.size!! > 0) {
                hangingBlueBeanList?.get(0)?.isSelect = true
                tv_basketNum.text = hangingBlueBeanList?.get(0)?.hanging_blue_name
                hanging_blue_id = hangingBlueBeanList?.get(0)?.id
            }
            getWorkmanShipList(building_id!!, facade_id!!, hanging_blue_id!!)


        }

    }

    private fun getFacadeList(buildingId: Int) {
        if (newProjectBeanList!!.size > 0) {
            facadeBeanList!!.clear()
            for (i in 0 until newProjectBeanList!!.size) {
                for (j in 0 until newProjectBeanList!![i].facade.size) {
                    if (newProjectBeanList!![i].facade[j].building_id == building_id) {
                        var facadeBean = FacadeBean()
                        facadeBean.facade_name = newProjectBeanList!![i].facade[j].facade_name
                        facadeBean.id = newProjectBeanList!![i].facade[j].id
                        facadeBeanList!!.add(facadeBean)
                    }

                }
            }
        }
    }

    private fun getHangingBlueList(building_id: Int, facade_id: Int) {
        if (newProjectBeanList!!.size > 0) {
            hangingBlueBeanList!!.clear()
            for (i in 0 until newProjectBeanList!!.size) {
                for (j in 0 until newProjectBeanList!![i].facade.size) {
                    for (k in 0 until newProjectBeanList!![i].facade[j].hanging_blue.size) {
                        if (newProjectBeanList!![i].facade[j].hanging_blue[k].building_id == building_id &&
                            newProjectBeanList!![i].facade[j].hanging_blue[k].facade_id == facade_id
                        ) {
                            var hangingBlueBean = HangingBlueBean()
                            hangingBlueBean.hanging_blue_name =
                                newProjectBeanList!![i].facade[j].hanging_blue[k].hanging_blue_name
                            hangingBlueBean.id =
                                newProjectBeanList!![i].facade[j].hanging_blue[k].id
                            hangingBlueBeanList!!.add(hangingBlueBean)
                        }
                    }
                }
            }
        }
    }

    private fun getWorkmanShipList(building_id: Int, facade_id: Int, hangingBlue_id: Int) {
        if (newProjectBeanList!!.size > 0) {
            workmanShipBeanList!!.clear()
//            constructionList!!.clear()
            for (i in 0 until newProjectBeanList!!.size) {
                for (j in 0 until newProjectBeanList!![i].facade.size) {
                    for (k in 0 until newProjectBeanList!![i].facade[j].hanging_blue.size) {
                        for (g in 0 until newProjectBeanList!![i].facade[j].hanging_blue[k].workmanship.size) {
                            if (newProjectBeanList!![i].facade[j].hanging_blue[k].building_id == building_id &&
                                newProjectBeanList!![i].facade[j].hanging_blue[k].facade_id == facade_id &&
                                newProjectBeanList!![i].facade[j].hanging_blue[k].workmanship[g].hanging_blue_id == hangingBlue_id
                            ) {
                                workmanShipBeanList!!.addAll(newProjectBeanList!![i].facade[j].hanging_blue[k].workmanship)
                            }
                        }

                    }
                }
            }
        }
        removeListDuplicate(workmanShipBeanList!! as ArrayList<Any>)
        recyclerView.adapter?.notifyDataSetChanged()
    }

    private fun getWorkmanShipId(projectBeanList: ArrayList<ProjectUploadDetailBean.DataBean>): Int {
        for (i in 0 until projectBeanList.size) {
            if (facade_id == projectBeanList.get(i).facade_id && building_id == projectBeanList.get(
                    i
                ).building_id &&
                hanging_blue_id == projectBeanList.get(i).hanging_blue_id
            ) {
                workmanship_id = projectBeanList.get(i).workmanship_id
            }
        }
        return workmanship_id!!
    }

    private fun getConstructionId(projectBeanList: ArrayList<ProjectUploadDetailBean.DataBean>): Int {
        for (i in 0 until projectBeanList.size) {
            if (facade_id == projectBeanList.get(i).facade_id && building_id == projectBeanList.get(
                    i
                ).building_id &&
                hanging_blue_id == projectBeanList.get(i).hanging_blue_id && workmanship_id == projectBeanList.get(
                    i
                ).workmanship_id
            ) {
                construction_id = projectBeanList.get(i).construction_id
            }
        }
        return construction_id!!
    }

    private fun getFacadeArrayValue(key: String): ArrayList<String> {
        var list = ArrayList<String>()
        for (index in 0 until projectBeanList?.size!!) {
            if (key.equals(projectBeanList?.get(index)?.building!!.building_name)) {
                list.add(projectBeanList?.get(index)?.facade!!.facade_name)
            }
        }
        return list
    }

    private fun getHangingBlueArrayValue(
        buildingkey: String,
        facadekey: String
    ): ArrayList<String> {
        var list = ArrayList<String>()
        for (index in 0 until projectBeanList?.size!!) {
            if (buildingkey.equals(projectBeanList?.get(index)?.building!!.building_name) &&
                facadekey.equals(projectBeanList?.get(index)?.facade!!.facade_name)
            ) {
                list.add(projectBeanList?.get(index)?.hanging_blue!!.hanging_blue_name)
            }
        }
        return list
    }

    //去重
    private fun removeListDuplicate(list: ArrayList<Any>): ArrayList<Any> {
        val h = HashSet(list)
        list.clear()
        list.addAll(h)
        return list
    }


}